package com.Interceptor;

import com.domain.UserInfo;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

public class myInterceptor implements HandlerInterceptor {
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();
        UserInfo loginUser = (UserInfo)session.getAttribute("user");
        if (loginUser != null)
            return true;
        request.getRequestDispatcher("/user/404").forward((ServletRequest)request, (ServletResponse)response);
        return false;
    }
}
